package chapter11;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 类本身作为监听器使用，使用该种方式继承对应的适配器写起来简单
 * 但是会造成该类无法继承其他类
 */
public class SimpleEventHandler extends WindowAdapter {
    private Frame frame = new Frame("测试");
    private TextArea ta = new TextArea(6, 40);
    public void init() {
        frame.addWindowListener(this);
        frame.add(ta);
        frame.pack();
        frame.setVisible(true);
    }

    @Override
    public void windowClosing(WindowEvent e) {
        ta.append("用户关闭窗口\n");
        System.exit(0);
    }

    public static void main(String[] args) {
        new SimpleEventHandler().init();
    }
}
